package com.huiyuanai.service.provider;

import com.huiyuanai.dao.Provider;
import com.huiyuanai.pojo.provider.ProviderPojo;
import com.huiyuanai.pojo.provider.ProviderPojoImpl;
import com.huiyuanai.util.BaseUtil;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Author: liwan
 * @Description:
 * @Date: create in 2021/10/17
 */
public class ProviderServiceImpl implements ProviderService {

    //service层调用pojo层
    ProviderPojo provider = null;

    public ProviderServiceImpl() {
        provider = new ProviderPojoImpl();
    }

    @Override
    public List<Provider> getProvider(String proCode, String proName, String id, int beginPage, int endPage) throws Exception {
        Connection connection = BaseUtil.getConnectionDIY();
        List<Provider> providerList = this.provider.getProvider(connection, proCode, proName, id,  beginPage, endPage);
        BaseUtil.clostResour(connection, null, null);
        return providerList;
    }

    @Override
    public int getCount(String proCode, String proName) throws Exception {
        Connection connection = BaseUtil.getConnectionDIY();
        int result = provider.getCount(connection, proCode, proName);
        BaseUtil.clostResour(connection, null, null);
        return result;
    }

    @Override
    public int upDataProvider(Provider provider) throws Exception {
        Connection connection = BaseUtil.getConnectionDIY();
        int result = this.provider.upDataProvider(connection, provider);
        BaseUtil.clostResour(connection, null, null);
        return result;
    }

    @Override
    public int addProvider(Provider provider) throws Exception {
        Connection connection = BaseUtil.getConnectionDIY();
        int result = 0;
        if (provider != null) {
            result = this.provider.addProvider(connection, provider);
        }
        return result;
    }

    @Override
    public int delProvider(String id) throws Exception {
        Connection connection = BaseUtil.getConnectionDIY();
        int result = provider.delProvider(connection, id);
        BaseUtil.clostResour(connection, null, null);
        return result;
    }


    @Test
    public void t() {
        ProviderServiceImpl providerService = new ProviderServiceImpl();
        try {
            providerService.delProvider("16");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
